package com.youlu.myapplication;

import android.graphics.Bitmap;

public class PngHandler {

    private long mPointer;

    public void init(String path) {
        mPointer = nativeInit(path);
    }

    public int getWidth() throws Exception {
        safeCheck();
        return nativeGetWidth(mPointer);
    }

    public int getHeight() throws Exception {
        safeCheck();
        return nativeGetHeight(mPointer);
    }

    public void updateBitmap(Bitmap bitmap) throws Exception {
        safeCheck();
        nativeUpdateBitmap(bitmap, mPointer);
    }

    private void safeCheck() throws Exception {
        if (mPointer <= 0) {
            throw new Exception("mPointer 未初始化");
        }
    }

    public void testBitmap(Bitmap bitmap) {

        nativeTestBitmap(bitmap);
    }

    private native void nativeUpdateBitmap(Bitmap bitmap, long address);

    private native long nativeInit(String path);

    private native int nativeGetWidth(long address);

    private native int nativeGetHeight(long address);

    private native void nativeTestBitmap(Bitmap bitmap);
}
